package com.biz;

import com.Interfacese.*;
import com.actionForm.*;
import com.dao.AlertUsers;
import com.dao.SaveProduct;
import com.dao.SaveUsers;
import com.dao.SearchUsers;

import entities.Product;
import entities.Users;

public class UserMessageHandle implements Register,SearchByNameAndCode,
										SearchByUserName ,AlertUserInterface,
										SaveUserByUserInterface{


	public void saveUser(Users u){
		SaveUsers su=new SaveUsers();
		try{
			su.saveUserByUser(u);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	public void alertUser(UserActionForm uaf,String name) {
		ActionFormToBean uftb=new ActionFormToBean();
		AlertUsers au = new AlertUsers();
		Users user=uftb.userActionFormToUserBean(uaf);
		try{
			au.alertUser(user,name);
		}catch(Exception e){
			e.printStackTrace();
		}
	}

	public boolean searchByNameAndCode(String name, String code) {
		try{
			return new SearchUsers().searchByNameAndCode(name, code);
		}catch(Exception e){
			e.printStackTrace();
		}
		return false;
	}

	public void register(UserActionForm obj) {
		ActionFormToBean uftb=new ActionFormToBean();
		SaveUsers su=new SaveUsers();
		Users u=uftb.userActionFormToUserBean(obj);
		try{//Handle Exception that save failing
			su.saveUser(u);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public Users searchByEmil(String email){
		SearchUsers su = new SearchUsers();
		Users u=su.searchByEmail(email);
		
		return u;
	}
	@Override
	public Users searchByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}
}
